﻿using MediatR;
using System.Threading;
using System.Threading.Tasks;
using wt.wine.Application.Common.Interfaces;
using wt.wine.Application.Common.Models;

namespace wt.wine.Application.ManageSkutable.Queries
{
    /// <summary>
    /// 商品列表
    /// </summary>
    public class GetSkuTableNameAddWineListQueries:IRequest<Json<PaginatedList<GetSkuTableNameAddWineListDTO>>>
    {
        /// <summary>
        /// 第几页
        /// </summary>
        public int pageIndex { get; set; }
        public int pageSize { get; set; }
    }

    public class GetSkuTableNameAddWineListQueriesHandler : IRequestHandler<GetSkuTableNameAddWineListQueries, Json<PaginatedList<GetSkuTableNameAddWineListDTO>>>
    {
        private readonly ICurrentUserService _icurrentUserServices;
        private readonly IskutableRepository _iskutableRepository;
        public GetSkuTableNameAddWineListQueriesHandler(ICurrentUserService icurrentUserServices, IskutableRepository iskutableRepository)
        {
            _icurrentUserServices = icurrentUserServices;
            _iskutableRepository = iskutableRepository;
        }
        public async Task<Json<PaginatedList<GetSkuTableNameAddWineListDTO>>> Handle(GetSkuTableNameAddWineListQueries request, CancellationToken cancellationToken)
        {
            int userid = _icurrentUserServices.GetUserId();
            if (request.pageIndex <= 0 || request.pageSize > 1000)
            {

                return Json<PaginatedList<GetSkuTableNameAddWineListDTO>>.Failed("参数异常");
            }
            else {
                var model = await _iskutableRepository.GetProductNameByAddWine(userid, request.pageIndex, request.pageSize, cancellationToken);
                return Json<PaginatedList<GetSkuTableNameAddWineListDTO>>.Success("操作成功",model);
            }
          
        }
    }
}
